package com.lnsf.service.impl;
/**
 * @author ddxing
 * @time 2017-7-26
 */
import java.util.Date;
import java.util.List;

import org.hibernate.sql.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;





import com.lnsf.dao.GoodsDao;
import com.lnsf.entity.Goods;
import com.lnsf.entity.User;
import com.lnsf.service.IGoodsService;

@Service
@Transactional
public class GoodsServiceImpl implements IGoodsService {
	
	@Autowired
	private GoodsDao goodsDao; 
	
	
	public void delete(Integer id){
		goodsDao.delete(id);
	}
	
	public Goods findOne(Integer id){
		return goodsDao.findOne(id);
	}
	
	public int update(int id,String name){
		return goodsDao.update(id, name);
	}
	
	public Goods save(Goods goods){
		goods.setStartTime(new Date());
		return goodsDao.save(goods);
	 }

	@Transactional(readOnly=true)
	public Page<Goods> getPage(int pageNo, int pageSize) {
		PageRequest pageable = new PageRequest(pageNo - 1, pageSize);
		return goodsDao.findAll(pageable);
	}
	
	/*
	 * 2017-7-27
	 * author:华炎
	 * 添加根据用户Id获取商品,提供给CommentController使用
	 */
	public List<Goods> findGoodsByUser(User user) {
		
		List<Goods> goodsList = goodsDao.findGoodsByUser(user.getId());
		
		return goodsList;
	}
	
}
